package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsMiddlePictureInfo;
import com.ruoyi.system.domain.news.query.NewsMiddlePictureInfoQuery;
import com.ruoyi.system.domain.news.vo.NewsMiddlePictureInfoVo;
import com.ruoyi.system.service.news.NewsMiddlePictureInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsMiddlePictureInfo")
@Api(value = "newsMiddlePictureInfoApiController", tags  = "中间图片新闻Api")
public class NewsMiddlePictureInfoApiController extends BaseController {

	@Resource
	private NewsMiddlePictureInfoService newsMiddlePictureInfoService;

	@ApiOperation(value = "获取单个中间图片新闻信息", notes = "获取单个中间图片新闻信息")
	@GetMapping("/getById")
	public R<NewsMiddlePictureInfo> getById(@RequestParam(value = "id") Long id) {
		NewsMiddlePictureInfoQuery newsMiddlePictureInfoQuery = new NewsMiddlePictureInfoQuery();
		newsMiddlePictureInfoQuery.setId(id);
		List<NewsMiddlePictureInfoVo> newsMiddlePictureInfoList = newsMiddlePictureInfoService.getNewsMiddlePictureInfoList(newsMiddlePictureInfoQuery);
		if (newsMiddlePictureInfoList!=null&&newsMiddlePictureInfoList.size()>0) {
			return R.ok(newsMiddlePictureInfoList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取中间图片新闻信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsMiddlePictureInfoVo>> list(@RequestBody NewsMiddlePictureInfoQuery newsMiddlePictureInfoQuery) {
        newsMiddlePictureInfoQuery.setIsEnable("1");
		List<NewsMiddlePictureInfoVo> newsMiddlePictureInfoList = newsMiddlePictureInfoService.getNewsMiddlePictureInfoList(newsMiddlePictureInfoQuery);
		return R.ok(new PageInfo<>(newsMiddlePictureInfoList));
	}
}
